//
//  PZTipsViewManger.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/12/4.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "PZTipsViewManger.h"
#import "PZTipsAlertView.h"
#import "PZTipsOverFlyView.h"
#import "PZTipsNullAlertView.h"



@implementation PZTipsViewManger



+(PZTipsAlertView *)shareDoubleTipsAlertViewTitle:(NSString *)title Mesage:(NSString *)message CancleTitle:(NSString *)cancleTitle SureTitle:(NSString *)sureTitle CancleBlock:(void (^)(void))cancleBlock SureBlock:(void (^)(void))sureBlock
{
    //    弹出双个按钮的提示框
    PZTipsAlertView *alert = [[PZTipsAlertView alloc] initWithTitle:title
                                                            message:message
                                                      constantWidth:LKScreenW - rate375(23) *2];
    
    PZAlertButton *cancelButton = [PZAlertButton buttonWithTitle:cancleTitle handler:^(PZAlertButton * _Nonnull button) {
        if (cancleBlock) {
            cancleBlock();
        }
    }];
    PZAlertButton *okButton = [PZAlertButton buttonWithTitle:sureTitle handler:^(PZAlertButton * _Nonnull button) {
        if (sureBlock) {
            sureBlock();
        }
    }];
    
  
    okButton.backgroundColor = [UIColor colorWithHexString:Orange];
    [okButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [cancelButton setTitleColor:[UIColor colorWithHexString:Orange] forState:UIControlStateNormal];
    
    okButton.edgeInsets = UIEdgeInsetsMake(18, 0, 0, 0);

   
   
    [alert adjoinWithLeftAction:okButton rightAction:cancelButton];
    
    return alert;
}


+(PZTipsAlertView *)shareSingleTipsAlertViewTitle:(NSString *)title Mesage:(NSString *)message ButtonTitle:(NSString *)buttonTitle ButtonClickBlock:(void (^)(void))buttonClickBlock
{
    
    
    PZTipsAlertView *alert = [[PZTipsAlertView alloc] initWithTitle:title message:message constantWidth:LKScreenW - rate375(23) *2];
    
    PZAlertButton *button = [PZAlertButton buttonWithTitle:buttonTitle handler:^(PZAlertButton * _Nonnull button) {
        if (buttonClickBlock) {
            buttonClickBlock();
        }
    }];
    button.edgeInsets = UIEdgeInsetsMake(20, 20, 25, 20);
    button.backgroundColor = [UIColor colorWithHexString:Orange];
    button.layer.cornerRadius = 5;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [alert addAction:button];
    return alert;
}
+(PZTipsNullAlertView *)shareNullTipsAlertViewTitle:(NSString *)title Mesage:(NSString *)message
{
    PZTipsNullAlertView *alert = [[PZTipsNullAlertView alloc] initWithTitle:title message:message constantWidth:LKScreenW - rate375(23) *2];
    return alert;
}
//
//标题内容不可为空，没有就传@""
+(PZTipsOverFlyView *)shareImageTipsOverFlyViewTitle:(NSString *)title SubTitle:(NSString *)subTitle Mesage:(NSString *)message CancleTitle:(NSString *)cancleTitle SureTitle:(NSString *)sureTitle CancleBlock:(void (^)(void))cancleBlock SureBlock:(void (^)(void))sureBlock
{
    NSString *text;
    if (title.length) {//有标题就换行，没有就不换
        text = [NSString stringWithFormat:@"%@\n%@", title, subTitle];
    }else{
        text = [NSString stringWithFormat:@"%@%@", title, subTitle];
    }
    
    NSMutableAttributedString *attiTitle = [[NSMutableAttributedString alloc] initWithString:text];
    //正标题
    [attiTitle addAttribute:NSForegroundColorAttributeName value:NumberColor(236, 78, 39) range:[text rangeOfString:title]];
    [attiTitle addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font20ScreenWRate *LKScreenW] range:[text rangeOfString:title]];
    //副标题
    [attiTitle addAttribute:NSForegroundColorAttributeName value:NumberColor(236, 78, 39) range:[text rangeOfString:subTitle]];
    [attiTitle addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font20ScreenWRate *LKScreenW] range:[text rangeOfString:subTitle]];
    
    [attiTitle addAttribute:NSKernAttributeName value:@1.2 range:[text rangeOfString:subTitle]];//字距调整
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:7];
    [attiTitle addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    
    
    NSMutableAttributedString *attiMessage = [[NSMutableAttributedString alloc] initWithString:message];
    [attiMessage addAttribute:NSKernAttributeName value:@0.5 range:NSMakeRange(0, [message length])];
    NSMutableParagraphStyle *paragraphStyle2 = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle2.alignment = NSTextAlignmentJustified;
    [paragraphStyle2 setLineSpacing:3];
    [attiMessage addAttribute:NSParagraphStyleAttributeName value:paragraphStyle2 range:NSMakeRange(0, [message length])];
    [attiMessage addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font14ScreenWRate *LKScreenW] range:NSMakeRange(0, [message length])];
    
    [attiMessage addAttribute:NSForegroundColorAttributeName value:NumberColor(49, 49, 39) range:NSMakeRange(0, [message length])];
    
    CGFloat fac = 475; // 已知透明区域高度
    UIImage *image = [UIImage imageNamed:@"fire_arrow"];
    
    PZTipsOverFlyView *overflyView = [[PZTipsOverFlyView alloc]
                                      initWithFlyImage:image
                                      highlyRatio:(fac / image.size.height)
                                      attributedTitle:attiTitle
                                      attributedMessage:attiMessage
                                      constantWidth:290];
    overflyView.layer.cornerRadius = 4;
    overflyView.messageEdgeInsets = UIEdgeInsetsMake(10, 22, 10, 22);
    overflyView.titleLabel.backgroundColor = [UIColor whiteColor];
    overflyView.titleLabel.textAlignment = NSTextAlignmentCenter;
    overflyView.splitLine.hidden = YES;
    [overflyView reloadAllComponents];
    
    
   
    PZOverflyButton *cancleButton = [PZOverflyButton buttonWithTitle:cancleTitle handler:^(PZOverflyButton * _Nonnull button) {
        if (cancleBlock) {
            cancleBlock();
        }
    }];
    [cancleButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    
    PZOverflyButton *sureButton = [PZOverflyButton buttonWithTitle:sureTitle handler:^(PZOverflyButton * _Nonnull button) {
        if (sureBlock) {
            sureBlock();
        }
    }];
    //#FC7541
    [sureButton setTitleColor:NumberColor(236, 78, 39) forState:UIControlStateNormal];
    cancleButton.lineColor = [UIColor colorWithHexString:@"#FC7541"];
    sureButton.lineColor = [UIColor colorWithHexString:@"#FC7541"];//
    sureButton.titleLabel.font = [UIFont systemFontOfSize:font16ScreenWRate *LKScreenW];
    
    if (cancleTitle.length) {
       [overflyView adjoinWithLeftAction:cancleButton  rightAction:sureButton];
    }else
    {
        [overflyView addAction:sureButton];
    }
    
    return overflyView;
  
}

@end
